package zju.ccnt.rest.domain;

import zju.ccnt.rest.api.ApiBusinessUser;
import zju.ccnt.rest.service.util.ServiceUtil;

import javax.persistence.Entity;

/**
 * Created by zha on 14/11/3.
 */
@Entity
public class BusinessUser extends BaseEntity{

    private String name;
    private String phone;
    private String address;
    private String router;
    private String parent;
    private String productTableName;
    private String password;

    public BusinessUser() {
        super();
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    private String email;

    public BusinessUser(ApiBusinessUser apiBusinessUser, String password) {
        super();
        this.name = apiBusinessUser.getName();
        this.phone = apiBusinessUser.getPhone();
        this.address = apiBusinessUser.getAddress();
        this.router = apiBusinessUser.getRouter();
        this.parent = apiBusinessUser.getParent();
        this.password = password;
        this.email = apiBusinessUser.getEmail();
        //todo productTableName表名规范
        this.productTableName = getViewName(email);
    }

    private String getViewName(String userEmail){
        return "product_" + ServiceUtil.getCleanEmail(userEmail);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getRouter() {
        return router;
    }

    public void setRouter(String router) {

        this.router = router;
    }

    public String getParent() {
        return parent;
    }

    public void setParent(String parent) {
        this.parent = parent;
    }

    public String getProductTableName() {
        return productTableName;
    }

    public void setProductTableName(String productTableName) {
        this.productTableName = productTableName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

}
